package org.wisigoth.chat.client.jabber;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.InetAddress;
import java.net.Socket;

public class Connection {

	private final InetAddress host;
	private final int port;
	private boolean connected = false;
	private Socket socket = null;

	public Connection(InetAddress host, int port) {
		this.host = host;
		this.port = port;
	}

	public void open() throws IOException {
		if (!this.connected) {
			this.socket = new Socket(this.host, this.port);
			this.connected = true;
		}
	}

	public void close() throws IOException {
		if (this.connected) {
			this.socket.close();
		}
	}

	public boolean isConnected() {
		return this.connected;
	}

	public InputStream getInputStream() throws IOException {
		return this.socket.getInputStream();
	}

	public OutputStream getOutputStream() throws IOException {
		return this.socket.getOutputStream();
	}
}
